package view.statique;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;

import javax.swing.JLabel;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;

public class JPStaticWebcam extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8695102985857372638L;
	private JLabel lblWebcam;

	/**
	 * Create the panel.
	 */
	public JPStaticWebcam() {
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{250, 0};
		gridBagLayout.rowHeights = new int[]{187, 0};
		gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		lblWebcam = new JLabel();
		GridBagConstraints gbc_lblWebcam = new GridBagConstraints();
		gbc_lblWebcam.fill = GridBagConstraints.BOTH;
		gbc_lblWebcam.gridx = 0;
		gbc_lblWebcam.gridy = 0;
		add(lblWebcam, gbc_lblWebcam);
	}

	public void setImage(Image i){
		BufferedImage bi = new BufferedImage(250, 187, BufferedImage.TYPE_INT_ARGB);
		Graphics g = bi.createGraphics();
		g.drawImage(i, 0, 0, 250, 187, null);
		ImageIcon newIcon = new ImageIcon(bi); 
		this.lblWebcam.setIcon(newIcon);
		this.repaint();
	}
}
